package com.hui.account.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hui.account.R;
import com.hui.account.utils.ButtonUtils;

import org.w3c.dom.Text;

public class PayMethodActivity extends AppCompatActivity implements View.OnClickListener {

    Button backBtn;

    TextView cashText, weChatText, aliPayText, bankText, otherText;

    SharedPreferences preferences; // preferences：共享参数，存储付款方式

    RelativeLayout cashLayout, weChatLayout, aliPayLayout, bankLayout, otherLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_method);

        // 1、设置屏幕顶部字体颜色
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

        // 2、页面初始化
        initView();

        // 5、preferences：共享参数初始化
        preferences = getSharedPreferences("shareParam", Context.MODE_PRIVATE);
    }

    private void initView() {
        backBtn = findViewById(R.id.pay_method_back);
        cashText = findViewById(R.id.pay_method_cash);
        weChatText = findViewById(R.id.pay_method_we_chat);
        aliPayText = findViewById(R.id.pay_method_ali_pay);
        bankText = findViewById(R.id.pay_method_bank);
        otherText = findViewById(R.id.pay_method_other);
        cashLayout = findViewById(R.id.pay_method_rl_1);
        weChatLayout = findViewById(R.id.pay_method_rl_2);
        aliPayLayout = findViewById(R.id.pay_method_rl_3);
        bankLayout = findViewById(R.id.pay_method_rl_4);
        otherLayout = findViewById(R.id.pay_method_rl_5);

        cashLayout.setOnClickListener(this);
        weChatLayout.setOnClickListener(this);
        aliPayLayout.setOnClickListener(this);
        bankLayout.setOnClickListener(this);
        otherLayout.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        SharedPreferences.Editor edit = preferences.edit();
        switch (view.getId()) {
            case R.id.pay_method_back:
                break;
            case R.id.pay_method_rl_1:
                edit.putString("payMethod", cashText.getText().toString());
                break;
            case R.id.pay_method_rl_2:
                edit.putString("payMethod", weChatText.getText().toString());
                break;
            case R.id.pay_method_rl_3:
                edit.putString("payMethod", aliPayText.getText().toString());
                break;
            case R.id.pay_method_rl_4:
                edit.putString("payMethod", bankText.getText().toString());
                break;
            case R.id.pay_method_rl_5:
                edit.putString("payMethod", otherText.getText().toString());
                break;
        }
        edit.commit();
        finish();
    }
}